package com.hooya.fa.eu.biz.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hooya.fa.eu.api.vo.SaleOrderPackageVO;
import com.hooya.fa.eu.api.vo.XsReportInfoVO;
import com.hooya.fa.eu.biz.dao.mapper.OrderReturnedMapper;
import com.hooya.fa.eu.biz.service.OrderEuService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Description 1
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2024/2/6
 * @Version 1.0.0
 */
@Slf4j
@Service
@DS("order_eu")
@AllArgsConstructor
public class OrderEuServiceImpl implements OrderEuService {

    private final OrderReturnedMapper orderReturnedMapper;

    @Override
    public List<String> getReturnedOrderIdsByDate(String startDate, CharSequence endDate) {
        return orderReturnedMapper.getReturnedOrderIdsByDate(startDate, endDate);
    }

    @Override
    public List<XsReportInfoVO> getXsReportInfoList(List<String> sheetNumberList) {
        return orderReturnedMapper.getXsReportInfoList(sheetNumberList);
    }

    @Override
    public Map<String, String> getLogisticsWayMapBySheetNumber(Set<String> sheetNumberList) {
        List<SaleOrderPackageVO> list = orderReturnedMapper.getLogisticsIdMapBySheetNumber(sheetNumberList);
        if (!CollectionUtils.isEmpty(list)) {
            return list.stream()
                    .collect(Collectors.toMap(SaleOrderPackageVO::getSheetNumber,
                            l -> StringUtils.isNotBlank(l.getLogisticsWay()) ? l.getLogisticsWay() : ""));
        }
        return new HashMap<>();
    }

    @Override
    public List<XsReportInfoVO> getXsReportInfoOtherList(List<String> sheetNumberList) {
        return orderReturnedMapper.getXsReportInfoOtherList(sheetNumberList);
    }
}
